package com.huyn.baseframework.dynamicload.video.model;

import com.huyn.baseframework.model.PicItem;
import com.huyn.baseframework.utils.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Created by huyaonan on 16/3/23.
 */
public class GoodsItem implements Serializable {

    public String tlTitle;
    public String goodsURL;
    public String tlDesc;
    public String type;
    public String price;
    public String _id;
    public String showid;
    public String goodstype="";
    public String goodstypedesc="";
    public String beforeDesc;
    public String afterDesc;
    public String showPicUrl;
    public String picurl;

    /**
     * replace picurl
     */
    public List<PicItem> picRespVoList;

//    public String getPrice() {
//        if(StringUtils.isBlank(price))
//            return "";
//        if(price.length() == 1)
//            return price;
//        char c = price.charAt(0);
//        if(c >= 49 && c <= 57)
//            return price;
//        else
//            return price.substring(1);
//    }

    public String getPic() {
        if(picRespVoList != null && picRespVoList.size() > 0)
            return picRespVoList.get(0).picurl;
        return "";
    }

    public int getPriceIndex() {
        if(StringUtils.isBlank(price))
            return -1;
        int i=0;
        while(i<price.length()) {
            char c = price.charAt(i);
            if (c >= 49 && c <= 57)
                return i;
            i++;
        }
        return -1;
    }

    public String parsePrice(int index) {
        return "<font><small>" + price.substring(0, index) + "</small></font>" + price.substring(index);
    }

}
